package com.code.google.mdsc.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

/**
 *
 */
@SuppressWarnings("serial")
public class ImagePanel extends JPanel {

	private BufferedImage image;

	/**
	 * @param file
	 */
	public ImagePanel(String file) {
		this.setBackground(Color.WHITE);
		try {

			image = ImageIO.read(getClass().getResourceAsStream(file));
			if (image != null)
				this.setPreferredSize(new Dimension(image.getWidth(), image
						.getHeight()));
		} catch (Exception ex) {
			ex.printStackTrace();
			// nothing to do here
			// TODO log
		}
	}

	@Override
	protected void paintComponent(Graphics g) {
		if (image != null) {

			super.paintComponent(g);
			g.drawImage(image, 0, 0, null);
		}
	}

}
